﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Business_projectpaused : System.Web.UI.Page
{
    PM.PMBusiness.projectpaused aproject = new PM.PMBusiness.projectpaused();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["planid"] != null)
            {
                string planid = Request.QueryString["planid"].ToString();
                this.labPlanId.Text = planid;
                if (Request.QueryString["new"] != null)
                {
                    //新建一个计划中断，左边的面板隐藏
                    this.showarea1.Visible = false;
                }
                else
                {
                    //获取未完成列表
                    GetUndoneList();
                }
                //获取计划内容
                GetProjectData(planid);
            }
            else
            {
                //获取未完成列表
                GetUndoneList();
                this.showarea2.InnerText = "没有任何信息";
            }
        }
    }

    protected void GetProjectData(string getid)
    {
        PM.Model.ProjectPlan proplan = new PM.Model.ProjectPlan();
        proplan = aproject.getAProject(getid);
        this.labPlanId.Text = proplan.plancode;
        this.labPlanId1.Text = proplan.plancode;
        this.labType.Text = proplan.typename;
        this.labPtype .Text = proplan.ptype;
        this.labLevel.Text = proplan.plevel;
        this.labOpenDate.Text = proplan.opendate.ToString();
        this.labCloseDate.Text = proplan.closedate.ToString();
        //查看有无教师申报项目
        this.RepFile.DataSource = aproject.getProjectFiles(proplan.plancode);
        this.RepFile.DataBind();
        this.labCount.Text = this.RepFile.Items.Count.ToString();
        if (this.RepFile.Items.Count == 0)
        {
            this.btnDel1.Enabled = false;
            this.btnDel2.Enabled = false;
            this.ddlTransPlan.Enabled = false;
        }
    }

    protected void GetUndoneList()
    {
        this.RepUndone.DataSource = aproject.getPausedProject();
        this.RepUndone.DataBind();
    }
    //文件转移
    protected void btntransfer_Click(object sender, EventArgs e)
    {
        if (this.labCount.Text != "0")
        {
            //加载同一类的数据
            aproject.bindTransType(this.ddlTransPlan, "2", this.labLevel.Text, this.labPtype.Text);
        }
        else
            this.ddlTransPlan.Enabled = false;
    }
    //选定了目标计划后
    protected void ddlTransPlan_SelectedIndexChanged(object sender, EventArgs e)
    {
        //开始文件的转移
        int result = aproject.Update_Planid(this.labPlanId1.Text.ToString().Trim(), this.ddlTransPlan.SelectedValue);
        if (result > 0)
        {
            this.div_note.InnerText = "共转移了文件"+result.ToString()+"个！";
            this.div_note.Attributes["class"]="note";
        }
    }
    //删除附件(即删除了整个项目计划)
    protected void btnDel1_Click(object sender, EventArgs e)
    {
         //删除项目计划，并且删除服务器上的文件
        int result = aproject.Delete_Planid(this.labPlanId1.Text.ToString().Trim());
        this.div_note.InnerHtml = "成功删除文件共" + result.ToString() + "个！";
        this.div_note.Attributes["class"] = "note";
        this.btnDel2.Enabled = false;
        this.btntransfer.Enabled = false;
    }
    protected void btnDel2_Click(object sender, EventArgs e)
    {
        //删除项目计划，并且删除服务器上的文件
        int result = aproject.Delete_Planid(this.labPlanId1.Text.ToString().Trim());
        this.div_note.InnerHtml = "成功删除文件共" + result.ToString() + "个！";
        this.div_note.Attributes["class"] = "note";
        this.btnDel1.Enabled = false;
        this.btntransfer.Enabled = false;
    }
}
